<template>
  <div>
    <home-header></home-header>
    <div ref="wrapper" class="home">
      <div>
        <home-swiper :swiperList="swiper"></home-swiper>
        <home-icons :iconsList="icons"></home-icons>
        <home-recommend :recommendList="recommend"></home-recommend>
        <home-weekend :weekendList="weekend"></home-weekend>
      </div>
    </div>
  </div>
</template>

<script>
import HomeHeader from './header/Header'
import HomeSwiper from './swiper/Swiper'
import HomeIcons from './icons/Icons'
import HomeRecommend from './recommend/Recommend'
import HomeWeekend from './weekend/Weekend'
import axios from 'axios'
import Bscroll from 'better-scroll'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      swiper: [],
      icons: [],
      recommend: [],
      weekend: [],
      lastCity: ''
    }
  },
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json?city=' + this.city).then(res => {
        this.swiper = res.data.data.swiperList
        this.icons = res.data.data.iconList
        this.recommend = res.data.data.recommendList
        this.weekend = res.data.data.weekendList
      })
    }
  },
  mounted () {
    this.getHomeInfo()
    this.scroll = new Bscroll(this.$refs.wrapper)
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  },
  computed: {
    ...mapState(['city'])
  }
}
</script>

<style scoped lang="stylus">
  .home
    position absolute
    top .87rem
    left 0
    right 0
    bottom 0
    overflow hidden
</style>
